/*
 * Copyright 2009-2010 Nanjing RedOrange ltd (http://www.red-orange.cn)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package redora.client.mvp;

/**
 * Base implementation of 'Place' in Google GWT's MVP. Additional to {@link com.google.gwt.place.shared.Place}
 * Places should implement a toString() which returns a url usable in the href attribute on an anchor.<br>
 * Central to redora's places is the name attribute, which is a lower case of the object (pojo) name.
 */
public abstract class Place extends com.google.gwt.place.shared.Place {
    public final String name;
    public Place(String name) {
        this.name = name(name);
    }

    /** @return Normalized class name (GWT does not support class.getSimpleName(). All in lowercase.*/
    public static String name(String name) {
        return name == null ? null : name.contains(".") ? name.substring(name.lastIndexOf(".") + 1).toLowerCase() : name;
    }

    public boolean equalsName(String name) {
        return name == null ? false : name(name).equals(this.name);
    }
}
